<!--页面主要内容-->
<main class="lyear-layout-content">
    <div class="container-fluid p-t-15">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-toolbar d-flex flex-column flex-md-row">
                        <div class="toolbar-btn-action">
                            <a class="btn btn-primary m-r-5" href="{:url('admin/admin/add')}"><i class="mdi mdi-plus"></i> 新增</a>
                            <a class="btn btn-success m-r-5 " href="javascript:void(0);"
                                target-form="ids"><i class="mdi mdi-check"></i> 启用</a>
                            <a class="btn btn-warning m-r-5" href="javascript:void(0);"><i class="mdi mdi-block-helper"></i> 禁用</a>
                            <a class="btn btn-danger dels" href="javascript:void(0);"><i class="mdi mdi-window-close"></i> 删除</a>
                        </div>

                        <form class="search-bar ml-md-auto" method="get" role="form">
                            <input type="hidden" name="search_field" id="search-field" value="username" />
                            <div class="input-group ml-md-auto">
                                <div class="input-group-prepend">
                                    <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"
                                        aria-haspopup="true" aria-expanded="false" id="search-btn">{$SearchField == 'username' ? '用户名' : '昵称'}</button>
                                    <div class="dropdown-menu" style="">
                                        <a class="dropdown-item" href="javascript:void(0);" data-field="username">用户名</a>
                                        <a class="dropdown-item" href="javascript:void(0);" data-field="nickname">昵称</a>
                                    </div>
                                </div>
                                <input type="text" class="form-control" name="keyword" placeholder="{$keyword}">
                            </div>
                        </form>
                    </div>
                    <div class="card-body">

                        <div class="table-responsive">
                            <table class="table table-bordered">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="custom-control custom-checkbox">
                                                <input type="checkbox" class="custom-control-input" id="check-all">
                                                <label class="custom-control-label" for="check-all"></label>
                                            </div>
                                        </th>
                                        <th>ID</th>
                                        <th>用户名</th>
                                        <th>昵称</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {if $AdminList}
                                        {foreach $AdminList as $item}
                                            <tr>
                                                <td>
                                                    <div class="custom-control custom-checkbox">
                                                        <input type="checkbox" class="custom-control-input ids" name="ids[]"
                                                            value="{$item.id}" id="ids-{$item.id}">
                                                        <label class="custom-control-label" for="ids-{$item.id}"></label>
                                                    </div>
                                                </td>
                                                <td>{$item.id}</td>
                                                <td>{$item.username}</td>
                                                <td>{$item.nickname}</td>
                                                <td>
                                                    <font class="{$item.state == 1 ? 'text-success' : 'text-warning'}">{$item.state ? '已启用' : '已禁用'}</font>
                                                </td>
                                                <td>
                                                    <div class="btn-group">
                                                        <a class="btn btn-xs btn-default" href="{:url('admin/admin/edit',['adminid' => $item.id])}" title=""
                                                            data-toggle="tooltip" data-original-title="编辑"><i
                                                                class="mdi mdi-pencil"></i></a>
                                                        <a class="btn btn-xs btn-default del"
                                                            href="javascript:void(0);" title=""
                                                            data-toggle="tooltip" data-adminid="{$item.id}" data-original-title="删除"><i
                                                                class="mdi mdi-window-close"></i></a>
                                                    </div>
                                                </td>
                                            </tr>
                                        {/foreach}
                                    {else /}
                                        暂无数据
                                    {/if}
                                </tbody>
                            </table>
                        </div>
                        {$AdminList|raw}
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!--End 页面主要内容-->
<script>
    $('.del').click(function(){
        $.confirm({
            title:'删除',
            content:'确认删除？删除后无法恢复',
            buttons:{
                confirm:{
                    text:'确认',
                    btnClass:'btn-info',
                    action:() =>
                    {
                        // 获取要删除的id
                        let adminid = $(this).data('adminid')

                        $.ajax({
                            type:'post',
                            url:`{:url('admin/admin/del')}`,
                            data:{
                                adminid
                            },
                            dataType:'json',
                            success:(result) => {
                                if(result.code === 1)
                                {
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'success',
                                        onClose:function()
                                        {
                                            location.reload();
                                        }
                                    })
                                }else{
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'warning'
                                    })
                                }
                            }
                        })
                        

                    }
                },
                cancel:{
                    text:'取消',
                    btnClass:'btn-danger'
                }
            }
        })
    })


    $('.dels').click(function(){
        $.confirm({
            title:'批量删除',
            content:'确认批量删除？删除后无法恢复',
            buttons:{
                confirm:{
                    text:'确认',
                    btnClass:'btn-info',
                    action:() =>
                    {
                        // 获取要删除的id
                        let adminid = GetId()

                        $.ajax({
                            type:'post',
                            url:`{:url('admin/admin/del')}`,
                            data:{
                                adminid
                            },
                            dataType:'json',
                            success:(result) => {
                                if(result.code === 1)
                                {
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'success',
                                        onClose:function()
                                        {
                                            location.reload()
                                        }
                                    })
                                }else{
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'warning'
                                    })
                                }
                            }
                        })
                        

                    }
                },
                cancel:{
                    text:'取消',
                    btnClass:'btn-danger'
                }
            }
        })
        
    })

    $('.btn-success').click(function(){
        $.confirm({
            title:'批量启用',
            content:'确认启用？',
            buttons:{
                confirm:{
                    text: '确认',
                    btnClass:'btn-info',
                    action:() => {
                        // 获取管理员id
                        let adminid = GetId()

                        $.ajax({
                            type:'post',
                            url:`{:url('admin/admin/state')}`,
                            data:{
                                adminid,
                                state:1
                            },
                            dataType:'json',
                            success:(result) => {
                                if(result.code === 1)
                                {
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'success',
                                        onClose:function()
                                        {
                                            location.reload()
                                        }
                                    })
                                }else{
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'warning'
                                    })
                                }
                            }
                        })

                    }
                },
                cancel:{
                    text:'取消',
                    btnClass:'btn-danger'
                }
            }
        })
    })


    $('.btn-warning').click(function(){
        $.confirm({
            title:'批量禁用',
            content:'确认禁用？',
            buttons:{
                confirm:{
                    text: '确认',
                    btnClass:'btn-info',
                    action:() => {
                        // 获取管理员id
                        let adminid = GetId()

                        $.ajax({
                            type:'post',
                            url:`{:url('admin/admin/state')}`,
                            data:{
                                adminid,
                                state:0
                            },
                            dataType:'json',
                            success:(result) => {
                                if(result.code === 1)
                                {
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'success',
                                        onClose:function()
                                        {
                                            location.reload()
                                        }
                                    })
                                }else{
                                    $.notify({
                                        message:result.msg,
                                    },{
                                        delay:1000,
                                        type:'warning'
                                    })
                                }
                            }
                        })

                    }
                },
                cancel:{
                    text:'取消',
                    btnClass:'btn-danger'
                }
            }
        })
    })

</script>